//
//  ExtensionTableViewCell.m
//  UIHomeWork19_汽车之家找车页
//
//  Created by tusm on 16/8/10.
//  Copyright © 2016年 tusm. All rights reserved.
//

#import "ExtensionTableViewCell.h"
#import "ExtensionCollectionViewCell.h"
@interface ExtensionTableViewCell()<UICollectionViewDelegate,UICollectionViewDataSource>
@property (nonatomic,strong)UICollectionView *collectionView;
@end
@implementation ExtensionTableViewCell
//为array赋值
- (void)setExtensionArray:(NSMutableArray<ExtensionList *> *)extensionArray{

    _extensionArray = extensionArray;
}
- (UICollectionView *)collectionView{
    
    if (!_collectionView) {
        UICollectionViewFlowLayout *flowLayOut = [[UICollectionViewFlowLayout alloc] init];
        flowLayOut.itemSize = CGSizeMake(90, 120);
        flowLayOut.minimumLineSpacing = 10;
        flowLayOut.minimumInteritemSpacing = 5;
        _collectionView = [[UICollectionView alloc] initWithFrame:self.contentView.bounds collectionViewLayout:flowLayOut];
        _collectionView.delegate = self;
        _collectionView.dataSource = self;
        [_collectionView registerClass:[ExtensionCollectionViewCell class] forCellWithReuseIdentifier:@"poolExtension"];
        //颜色
        _collectionView.backgroundColor = [UIColor whiteColor];
        _collectionView.alwaysBounceHorizontal = YES;
    }
    return _collectionView;
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
    NSLog(@"%@", NSStringFromCGRect(self.contentView.bounds));
        [self.contentView addSubview:self.collectionView];
    }
    return self;
}


- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    return _extensionArray.count;

}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{

    ExtensionCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"poolExtension" forIndexPath:indexPath];
    
    cell.extensionList = self.extensionArray[indexPath.row];
    return cell;

}
- (void)layoutSubviews{

    [super layoutSubviews];
    self.collectionView.frame = self.contentView.bounds;
}






- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
